package com.xudow.app.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.activeshare.edu.ucenter.models.base.AgencySchools;
import com.xudow.app.R;

import java.util.List;

/**
 * Created by Administrator on 2016/5/15.
 */
public class AgencySchoolsAdapter extends BaseAdapter {
    private Context context;
    private List<AgencySchools> data;
    public void setData(List<AgencySchools> data){
        this.data=data;
    }
    public AgencySchoolsAdapter(Context context, List<AgencySchools> objects) {
        this.context=context;
        this.data=objects;
    }
    @Override
    public int getCount() {
        if (null==data)
            return 0;
        else
            return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (null == convertView) {
            convertView = View.inflate(context,R.layout.layout_course_area, null);

            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        AgencySchools item = (AgencySchools) getItem(position);
        holder.name.setText(item.getName());
        Log.e("getView: ", "schoolName"+item.getName());

        if (item.selected) {
            holder.icon.setVisibility(View.VISIBLE);
        } else {
            holder.icon.setVisibility(View.GONE);
        }

        return convertView;
    }

    private class ViewHolder {
        public TextView name;
        private ImageView icon;
    }
}
